package com.bym.mall.utils;

import com.bym.mall.vo.UserVo;

public class UserUtil {

    /**
     * 保存user的ThreadLocal
     */
    private static final ThreadLocal<UserVo> userThreadLocal = new ThreadLocal<>();

    /**
     * 将当前user添加至ThreadLocal
     */
    public static void addUser(UserVo userVo) {
        userThreadLocal.set(userVo);
    }

    /**
     * 从ThreadLocal中获取当前user
     */
    public static UserVo getUser() {
        return userThreadLocal.get();
    }


    /**
     * 从ThreadLocal中删除当前user（防止内存泄露）
     */
    public static void removeUser() {
        userThreadLocal.remove();
    }
}
